$(function(){
    $.validator.setDefaults({
        ignore: []
    });
    $("#setform").validate({
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        }
    });
    if(dev) {
        console.info("userinfo init js");
    }
    getData('POST',interfaces.userinfo,true,'{"token":"'+$.cookie("token")+'"}','settings');
    $('body').delegate('.save','click',function(){

        if($("#setform").validate().form()){
            //var name=$('#name').val();
            var firstName=$('#firstName').val();
            var middleName=$('#middleName').val();
            var lastName=$('#lastName').val();
            var email=$('#email').val();
            //var gender=$('#gender').val();
            //var location=$('#location').val();
            //var phone=$('#phone').val();
            var website=$('#website').val();
            var institu=$('#institu').val();
            var department=$('#department').val();
            //var organ=$('#organ').val();
            var interests=$('#interests').val();
            var interarr=new Array();
            if(interests!=undefined&&interests!=""){
                interarr= interests.split(',');
            }
            if(dev) {
                console.info(interarr);
            }
            var data=new Object();
            data['token']=$.cookie('token');
            //data['username']=name;
            data['firstName']=firstName;
            data['middleName']=middleName;
            data['lastName']=lastName;
            data['email']=email;
            //data['gender']=gender;
            //data['position']=location;
            //data['phone']=phone;
            data['homepage']=website;
            data['institution']=institu;
            data['department']=department;
            data['interests']=interarr;

            /*var data2='{"token":"'+ $.cookie('token')+'","username":"'+name+'","email":"'+email
                +'","gender":"'+gender+'","position":"'+location+'","phone":"'+phone+'","homepage":"'+website
                +'","department":"'+organ+'","interests":'+interarr+'}';*/
            getData('POST',interfaces.account_settings,true,JSON.stringify(data),'settings2');
        }

    });

});